const puppeteer = require('puppeteer');
const endpoint = require('./endpoint');

const sleep = function(time) {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      resolve();
    }, time);
  });
};

const test = async () => {

  const defaultViewport = {
    deviceScaleFactor: 1,
    hasTouch: false,
    height: 1024,
    isLandscape: false,
    isMobile: false,
    width: 1280,
  };

  const browser = await puppeteer.connect(
    {browserWSEndpoint: endpoint.browserWSEndpoint, ignoreHTTPSErrors: false});

  console.log(`browser URL = ${browser._connection.url()}`);
  const pages = await browser.pages();
  const page = pages[0];
  await page.setViewport(defaultViewport);
  await page.goto('https://coin.jd.com/asset/sc/myassets.html');
  // p = page.waitForNavigation({waitUntil: 'networkidle0'});
  await page.click('div.login-tab.login-tab-r');

  console.log(`next`);

  // await sleep(100000 * 1000);
  // await browser.close();
};

test().then(() => {}).catch(err => {
  console.log(err);
});
